define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie'], function ($, undefined, Backend, Table, Form, Template, undefined) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.length > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            info: function () {
            },
            visit: function () {
                // 表格2
                var table2 = $("#table2");
                table2.bootstrapTable({
                    url: 'business/privateseainfo/Visitindex?busid='+Fast.api.query('ids'),
                    extend: {
                        index_url: 'business/privateseainfo/Visitindex?busid='+Fast.api.query('ids'),
                        add_url: 'business/privateseainfo/add?busid='+Fast.api.query('ids'),
                        edit_url: 'business/privateseainfo/edit',
                        del_url: 'business/privateseainfo/del',
                        table: 'business_visit',
                    },
                    toolbar: '#toolbar2',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            { checkbox: true },
                            { field: 'id', title: __('Id'), sortable: true },
                            { field: 'business.nickname', title: __('Nickname'), operate: 'LIKE' },
                            { field: 'content', title: __('Content') },
                            { field: 'admin.nickname', title: __('Adminid'),searchList:$.getJSON("business/privateseainfo/admin")  },
                            { field: 'createtime', title: __('Vcreatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                            {
                                field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            }
                        ]
                    ]
                });
                    // 为表格2绑定事件
                    Table.api.bindevent(table2);
            },
            apply: function () {
                // 表格1
                var table3 = $("#table3");
                table3.bootstrapTable({
                    url: 'business/receive/index?busid='+Fast.api.query('ids'),
                    extend: {
                        index_url: 'business/receive/index?busid='+Fast.api.query('ids'),
                        table: 'business_receive',
                    },
                    toolbar: '#toolbar3',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            { checkbox: true },
                            { field: 'id', title: __('Id'), sortable: true },
                            { field: 'business.nickname', title: __('Nickname'), operate: 'LIKE' },
                            { field: 'admin.nickname', title: __('Applyid'), searchable:false},
                            { field: 'status', title: __('Status'), searchList: { "apply": __('申请'), "allot": __('分配'), "recovery": __('回收'), "reject": __('拒绝') },formatter: Table.api.formatter.status },
                            { field: 'applytime', title: __('Applytime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table3);
            },
        },
        // 添加
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        restore: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});
